package ai.people.netmon.telegram.service.impl;

import ai.people.netmon.framework.domain.telegram.entity.AnalysisDataUser;
import ai.people.netmon.framework.businessenum.AnalysisSourceEnum;
import ai.people.netmon.framework.businessenum.AnalysisTypeEnum;
import ai.people.netmon.telegram.mapper.AnalysisDataUserMapper;
import ai.people.netmon.telegram.service.AnalysisDataUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 分析数据用户服务impl
 *
 * @author yuanqinglong
 * @date 2022/1/18 16:01
 */
@Service
public class AnalysisDataUserServiceImpl implements AnalysisDataUserService {


    @Autowired
    private AnalysisDataUserMapper analysisDataUserMapper;


    /**
     * 加入分析
     *
     * @param analysisDataUser 分析数据用户
     * @return int
     */
    @Override
    public int joinAnalysis(AnalysisDataUser analysisDataUser) {
        return analysisDataUserMapper.insert(analysisDataUser);
    }

    /**
     * 取消分析
     *
     * @param analysisDataUser 分析数据用户
     * @return int
     */
    @Override
    public int cancelAnalysis(AnalysisDataUser analysisDataUser) {
        LambdaQueryWrapper<AnalysisDataUser> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(AnalysisDataUser::getAnalysisTargetId, analysisDataUser.getAnalysisTargetId()).eq(AnalysisDataUser::getUserId, analysisDataUser.getUserId())
                .eq(AnalysisDataUser::getAnalysisSource, AnalysisSourceEnum.telegram.name()).eq(AnalysisDataUser::getAnalysisType, AnalysisTypeEnum.CHANNELS.getCode());
        return analysisDataUserMapper.delete(lambdaQuery);
    }


}
